home *** CD-ROM | disk | FTP | other *** search
Wrap
/* RequestBot.rexx This is a robot that lets you request textfiles that are then sent to you as a netmail. The robot understand two commands: %GET <file> Requests a textfile %LIST Lists all available textfiles Configure as "rx RequestBot.rexx %r" (with path if needed) in CrashPrefs. */ /* Configuration */ crashwrite = "Work:UMS/CrashMail/CrashWrite" inbound = "MAIL:Inbound" listformat = "%-20.20s %7l %.50c" /* Passed to c:list as lformat */ directory = "MAIL:Text" /* Enf of configuration */ if right(directory,1)~=":" & right(directory,1)~="/" then do directory=directory || "/" end IF ~SHOW(Libraries,'rexxsupport.library') THEN IF ~ADDLIB("rexxsupport.library",0,-30,0) THEN EXIT parse arg file kg=TRUE to="" toaddr="" from="" fromaddr="" call open('file',file,'R') do while kg=TRUE str = readln('file') if eof('file') then do kg=FALSE end else if length(str)=0 then do kg=FALSE end else do if left(str,5)="From:" then parse var str 'From: 'fromaddr'@'dummy' ('fromname')' if left(str,3)="To:" then parse var str 'To: 'toaddr'@'dummy' ('toname')' end end call open('out','T:RequestBot.tmp','W') kg=TRUE do while kg=TRUE str = readln('file') if left(str,3)="---" then do kg=FALSE end else if left(str,1)="%" then do parse var str "%"command" "file parse upper var command command if command='GET' then do if pos(":",file)~=0 | pos("/",file)~=0 then do call writeln('out',left(str,20) || "Illegal file name") end else if exists(directory||file) then do address command crashwrite 'FN "RequestBot" FA 'toaddr' TN "'fromname'" TA 'fromaddr' SUBJ "'file'" DIR "'inbound'"' directory||file call writeln('out',left(str,20) || "File sent") end else do call writeln('out',left(str,20) || "File not found") end end else if command='LIST' then do address command 'c:list >T:RequestList.tmp' directory 'lformat "'listformat'"' address command crashwrite 'FN "RequestBot" FA 'toaddr' TN "'fromname'" TA 'fromaddr' SUBJ "List of available files" DIR "'inbound'" T:RequestList.tmp' call writeln('out',left(str,20) || "List sent") call delete("T:RequestList.tmp") end else do call writeln('out',left(str,20) || "Unknown command") end end if eof('file') then do kg=FALSE end end call close('file') call close('out') /* Send the mail using CrashWrite */ address command crashwrite 'FN "RequestBot" FA 'toaddr' TN "'fromname'" TA 'fromaddr' SUBJ "Response to your request" DIR "'inbound'" T:RequestBot.tmp' call delete("T:RequestBot.tmp") address command 'Run >NIL: <NIL: rx "address 'CRASHMAIL' toss"' exit 10